package entities;

import java.util.ResourceBundle;
import java.util.Vector;

import util.DateFormatting;
import bundles.BundleLoader;

/**
 * Entity Class for Members. Role can be Player or Coach.
 * 
 * @author MK
 * 
 */
public class Member {

	private String nameFirst;
	private String nameLast;
	private Long dateOfBirth;
	private Address address;
	private String eMail;
	private String phoneHome;
	private String phoneMobile;
	private String state;
	private String position;
	private String role;

	private Member() {
		super();
	}

	public Member(String nameFirst, String nameLast, Long dateOfBirth,
			Address address, String eMail, String phoneHome,
			String phoneMobile, String state, String position, String role) {

		this.nameFirst = nameFirst;
		this.nameLast = nameLast;
		this.dateOfBirth = dateOfBirth;
		this.address = address;
		this.eMail = eMail;
		this.phoneHome = phoneHome;
		this.phoneMobile = phoneMobile;
		this.state = state;
		this.position = position;
		this.role = role;
	}

	public Member(Member member) {
		this(member.nameFirst, member.nameLast, member.dateOfBirth,
				member.address, member.eMail, member.phoneHome,
				member.phoneMobile, member.state, member.position, member.role);
	}

	public Member(String nameFirst, String nameLast) {
		this.nameFirst = nameFirst;
		this.nameLast = nameLast;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((dateOfBirth == null) ? 0 : dateOfBirth.hashCode());
		result = prime * result
				+ ((nameFirst == null) ? 0 : nameFirst.hashCode());
		result = prime * result
				+ ((nameLast == null) ? 0 : nameLast.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Member other = (Member) obj;
		if (dateOfBirth == null) {
			if (other.dateOfBirth != null)
				return false;
		} else if (!dateOfBirth.equals(other.dateOfBirth))
			return false;
		if (nameFirst == null) {
			if (other.nameFirst != null)
				return false;
		} else if (!nameFirst.equals(other.nameFirst))
			return false;
		if (nameLast == null) {
			if (other.nameLast != null)
				return false;
		} else if (!nameLast.equals(other.nameLast))
			return false;
		return true;
	}

	@Override
	public String toString() {

		return "Member [address=" + address + ", dateOfBirth=" + dateOfBirth
				+ ", eMail=" + eMail + ", nameFirst=" + nameFirst
				+ ", nameLast=" + nameLast + ", phoneHome=" + phoneHome
				+ ", phoneMobile=" + phoneMobile + ", position=" + position
				+ ", role=" + role + ", state=" + state + "]";
	}

	public int compareTo(Member member) {
		if (this.nameFirst.compareTo(member.nameFirst) == 0
				&& this.nameLast.compareTo(member.nameLast) == 0
				&& this.dateOfBirth.compareTo(member.dateOfBirth) == 0) {
			return 0;
		} else {
			if (this.nameLast.compareTo(member.nameLast) != 0) {
				return this.nameLast.compareTo(member.nameLast);
			} else {
				return this.nameFirst.compareTo(member.nameFirst);
			}
		}
	}

	public Vector<String> asVector() {
		ResourceBundle resBundle = BundleLoader.getResourceBundle();

		Vector<String> vector = new Vector<String>();

		vector.add(this.nameLast);
		vector.add(this.nameFirst);
		vector.add(resBundle.getString(position));
		vector.add(DateFormatting.toFormattedStringOnlyDate(this.dateOfBirth));
		vector.add(this.address.toString());
		vector.add(resBundle.getString(state));

		return vector;
	}

	public Vector<String> asShortVector() {
		ResourceBundle resBundle = BundleLoader.getResourceBundle();

		Vector<String> vector = new Vector<String>();

		vector.add(this.nameLast);
		vector.add(this.nameFirst);
		vector.add(resBundle.getString(state));

		return vector;
	}

	public static Vector<String> attributeNames() {
		ResourceBundle resBundle = ResourceBundle
				.getBundle("bundles.MessagesBundle");

		Vector<String> vector = new Vector<String>();
		vector.add(resBundle.getString("nameLast"));
		vector.add(resBundle.getString("nameFirst"));
		vector.add(resBundle.getString("position"));
		vector.add(resBundle.getString("dateOfBirth"));
		vector.add(resBundle.getString("address"));
		vector.add(resBundle.getString("state"));

		return vector;
	}

	public static Vector<String> attributeNamesShort() {
		ResourceBundle resBundle = ResourceBundle
				.getBundle("bundles.MessagesBundle");

		Vector<String> vector = new Vector<String>();
		vector.add(resBundle.getString("nameLast"));
		vector.add(resBundle.getString("nameFirst"));
		vector.add(resBundle.getString("state"));

		return vector;
	}

	public String getNameFirst() {
		return nameFirst;
	}

	public String getNameLast() {
		return nameLast;
	}

	public Long getDateOfBirth() {
		return dateOfBirth;
	}

	public Address getAddress() {
		return address;
	}

	public String geteMail() {
		return eMail;
	}

	public String getPhoneHome() {
		return phoneHome;
	}

	public String getPhoneMobile() {
		return phoneMobile;
	}

	public String getState() {
		return state;
	}

	public String getPosition() {
		return position;
	}

	public String getRole() {
		return role;
	}

	public void setAddress(Address address) {
		this.address = address;
	}

	public void seteMail(String eMail) {
		this.eMail = eMail;
	}

	public void setPhoneHome(String phoneHome) {
		this.phoneHome = phoneHome;
	}

	public void setPhoneMobile(String phoneMobile) {
		this.phoneMobile = phoneMobile;
	}

	public void setState(String state) {
		this.state = state;
	}

	public void setPosition(String position) {
		this.position = position;
	}

	public void setRole(String role) {
		this.role = role;
	}
}